home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / MacLib / MacLib.c next >
Encoding:
C/C++ Source or Header  |  1994-01-08  |  8.4 KB  |  343 lines  |  [TEXT/KAHL]

  1. /*    Functions for determining features of the operating environment.
  2.  
  3.     Revision History:
  4.     
  5.     94/01/08 aih
  6.     - added test for temporary memory
  7.     
  8.     93/12/28 aih
  9.     - split gestalt functions into a separate file
  10.     - removed a few unneeded functions
  11.     
  12.     93/03/25 AIH
  13.     - Added check for Notification Manager and FindFolder
  14.     - Moved application, INIT, and DA initialization code into
  15.     different libraries
  16.     
  17.     93/03/12 AIH
  18.     - Added checks for console and profiler
  19.  
  20.     93/03/10 AIH
  21.     - Added checks for AE manager, aliases, and FSSpec calls
  22.     
  23.     91/11/15 AIH
  24.     - Changed check for TMON's presence to use Gestalt to determine if TMON
  25.     Professional is installed (as described in the TMON manual).
  26.     
  27.     91/11/14 AIH
  28.     - Removed checks for system software version 7.0
  29.     - Functions for determining the facilities of QuickDraw return
  30.     correct values (ie, they don't always return the original QD version)
  31.  
  32.     91/06/13 AIH
  33.     - Functions for determining facilities of QuickDraw always return
  34.     values for the original QuickDraw since I don't have a newer machine
  35.     to test color QuickDraw things on
  36.     
  37.     91/06/12 AIH
  38.     - Fixed return value from function for getting version of QuickDraw:
  39.     I had forgotten to put the return statement in the function
  40.     
  41.     91/06/01 AIH
  42.     - Added function to return the reference number of the application
  43.     
  44.     91/05/27 AIH
  45.     - Added function to determine if FSSpec records are supported by the
  46.     File Manager
  47.     
  48.     91/05/18 AIH
  49.     - Added function to return the version of QuickDraw
  50.     
  51.     91/05/17 AIH
  52.     - Enhanced function for getting version of A/UX so it will work
  53.     with pre-2.0 versions of A/UX.
  54.     
  55.     91/05/13 AIH
  56.     - Added functions to determine if multiple screens are supported
  57.     
  58.     91/05/07 AIH
  59.     - InitCursor is not called as soon as the managers have been
  60.     initialized since a lot of other initialization still has to
  61.     be done
  62.     
  63.     91/04/28 AIH
  64.     - Added function for testing for Apple event manager
  65.     
  66.     91/04/20 AIH
  67.     - Gestalt manager is used where appropriate
  68.     - Upgraded required system version to 6.0.4 so that Gestalt manager can
  69.     always be used
  70.     - Put all global variables used in this library into a single structure
  71.     - Changed some function names to make their purpose clearer
  72.     
  73.     91/04/18 AIH
  74.     - Added function to determine if notification manager is available
  75.     
  76.     91/03/25 AIH
  77.     - To speed up use of environs info, SysEnvirons is only called if necessary
  78.     
  79.     91/03/23 AIH
  80.     - Updated for 7.0 headers
  81.     
  82.     91/03/11 AIH
  83.     - Got rid of function to determine if a program is executing as an
  84.     application, INIT, or DA
  85.     - Sysenvirons data are stored in a single static variable
  86.     
  87.     91/01/28 AIH
  88.     - Added function to determine if a program is executing as an application,
  89.     INIT, or DA
  90.     
  91.     91/01/31 AIH
  92.     - Moved time functions into a time library, and moved stack and heap size
  93.     functions into memory library
  94.     
  95.     91/01/27 AIH
  96.     - Added functions for getting stack and heap sizes
  97.     
  98.     91/01/25 AIH
  99.     - MacInitINIT can take a pointer to the QuickDraw globals if InitGraf
  100.     has already been called
  101.     - Removed call to SetApplLimit from MacInitINIT since the neccessary low
  102.     memory globals have not been initialized.
  103.     
  104.     91/01/21 (or earlier) AIH
  105.     - Adapted MacInit to three versions: for an application, an INIT, and 
  106.     a DA. Using these functions, you will always be assured of access to the
  107.     QuickDraw globals.
  108.     
  109.     91/01/05 Ari Halberstadt (AIH)
  110.     - Inserted this standard header in all files */
  111.  
  112. #include <GestaltEqu.h>
  113. #include "GestaltLib.h"
  114. #include "LowMemLib.h"
  115. #include "TrapLib.h"
  116. #include "MacLib.h"
  117.  
  118. /*----------------------------------------------------------------------------*/
  119. /* information about the macintosh */
  120. /*----------------------------------------------------------------------------*/
  121.  
  122. /* information about the macintosh */
  123. typedef struct {
  124.     SysEnvRec    world;            /* environment information */
  125.     short            appRefNum;        /* application's reference number */
  126.     short            appVRefNum;        /* application's volume reference number */
  127. } MacDataType;
  128.  
  129. /* initialize environment data */
  130. static void MacDataInit(MacDataType *data)
  131. {
  132.     Str255 volname;
  133.  
  134.     /* remember application's reference number (this works even when debugging
  135.         under THINK C) and volume reference number */
  136.     data->appRefNum = CurResFile();
  137.     GetVol(volname, &data->appVRefNum);
  138.     (void) SysEnvirons(curSysEnvVers, &data->world);
  139. }
  140.  
  141. /* return information about the operating environment */
  142. static MacDataType *MacData(void)
  143. {
  144.     static Boolean initialized;
  145.     static MacDataType data;
  146.     
  147.     if (! initialized) {
  148.         MacDataInit(&data);
  149.         initialized = true;
  150.     }
  151.     return(&data);
  152. }
  153.  
  154. /*----------------------------------------------------------------------------*/
  155. /* application and system volume reference numbers */
  156. /*----------------------------------------------------------------------------*/
  157.  
  158. /* return the volume reference number of the system folder */
  159. short MacSysVRef(void)
  160. {
  161.     /* call SysEnvirons since sysVRefNum can change during execution */
  162.     (void) SysEnvirons(curSysEnvVers, &MacData()->world);
  163.     return(MacData()->world.sysVRefNum);
  164. }
  165.  
  166. /* return the volume reference number of the application folder */
  167. short MacAppVRef(void)
  168. {
  169.     return(MacData()->appVRefNum);
  170. }
  171.  
  172. /* return the reference number of the application file */
  173. short MacAppRefNum(void)
  174. {
  175.     return(MacData()->appRefNum);
  176. }
  177.  
  178. /* get the name of the application */
  179. void MacAppName(CStr255 name)
  180. {
  181.     short ref;
  182.     Handle param;
  183.     
  184.     GetAppParms((StringPtr) name, &ref, ¶m);
  185.     p2cstr((StringPtr) name);
  186. }
  187.  
  188. /*----------------------------------------------------------------------------*/
  189. /* version information */
  190. /*----------------------------------------------------------------------------*/
  191.  
  192. short MacVersion(void)
  193. {
  194.     return(MacData()->world.systemVersion);
  195. }
  196.  
  197. short MacVersionAUX(void)
  198. {
  199.     short result = 0;
  200.     
  201.     if (MacHasGestalt())
  202.         result = LoWord(GestaltResponse(gestaltAUXVersion));
  203.     else if (GetHWCfgFlags() & (1<<9))
  204.         result = 0x0100; /* assume version 1.0 */
  205.     return(result);
  206. }
  207.  
  208. short MacVersionQD(void)
  209. {
  210.     long response = 0;
  211.     short result = gestaltOriginalQD;
  212.     
  213.     if (MacHasGestalt())
  214.         result = LoWord(GestaltResponse(gestaltQuickdrawVersion));
  215.     else if (MacData()->world.hasColorQD)
  216.         result = gestalt8BitQD;
  217.     return(result);
  218. }
  219.  
  220. /*----------------------------------------------------------------------------*/
  221. /* operating capabilities */
  222. /*----------------------------------------------------------------------------*/
  223.  
  224. Boolean MacHasGestalt(void)
  225. {
  226.     return(GestaltAvailable());
  227. }
  228.  
  229. Boolean MacHasWNE(void)
  230. {
  231.     static Boolean initialized;
  232.     static Boolean wne;
  233.     
  234.     if (! initialized) {
  235.         /* do only once for efficiency */
  236.         wne = TrapAvailable(_WaitNextEvent);
  237.         initialized = true;
  238.     }
  239.     return(wne);
  240. }
  241.  
  242. Boolean MacHasColor(void)
  243. {
  244.     /* program_note: needs to be tested on color machines */
  245.     #ifdef COLOR
  246.         return(MacVersionQD() >= gestalt8BitQD);
  247.     #else
  248.         return(false);
  249.     #endif
  250. }
  251.  
  252. Boolean MacHasMultipleScreens(void)
  253. {
  254.     return(MacHasColor());
  255. }
  256.  
  257. Boolean MacHasSingleScreen(void)
  258. {
  259.     return(! MacHasMultipleScreens());
  260. }
  261.  
  262. Boolean MacHasTMON(void)
  263. {
  264.     /*    See "TMON Professional Reference", section 9.4.1 "Testing for
  265.         Monitor Presence" (1990, ICOM Simulations, Inc). This only
  266.         works with version 3.0 or later of TMON. */
  267.     return(GestaltResponse('TMON') != 0);
  268. }
  269.  
  270. Boolean MacHasMacsBug(void)
  271. {
  272.     /* program_note: doesn't work with macsbug 6.2.2 */
  273.     return(GestaltBitTst(gestaltOSAttr, gestaltSysDebuggerSupport));
  274. }
  275.  
  276. Boolean MacHasDebugger(void)
  277. {
  278.     return((MacHasMacsBug() || MacHasTMON()));
  279. }
  280.  
  281. Boolean MacHasAUX(void)
  282. {
  283.     return(MacVersionAUX() > 0);
  284. }
  285.  
  286. Boolean MacHasAppleEvents(void)
  287. {
  288.     return(GestaltBitTst(gestaltAppleEventsAttr, gestaltAppleEventsPresent));
  289. }
  290.  
  291. Boolean MacHasAliases(void)
  292. {
  293.     return(GestaltBitTst(gestaltAliasMgrAttr, gestaltAliasMgrPresent));    
  294. }
  295.  
  296. Boolean MacHasFSSpec(void)
  297. {
  298.     return(GestaltBitTst(gestaltFSAttr, gestaltHasFSSpecCalls));    
  299. }
  300.  
  301. Boolean MacHasStandardFile(void)
  302. {
  303.     return(GestaltBitTst(gestaltStandardFileAttr, gestaltStandardFile58));    
  304. }
  305.  
  306. Boolean MacHasHelpManager(void)
  307. {
  308.     return(GestaltBitTst(gestaltHelpMgrAttr, gestaltHelpMgrPresent));    
  309. }
  310.  
  311. Boolean MacHasNotificationMgr(void)
  312. {
  313.     return(GestaltBitTst(gestaltNotificationMgrAttr, gestaltNotificationPresent));
  314. }
  315.  
  316. Boolean MacHasFindFolder(void)
  317. {
  318.     return(GestaltBitTst(gestaltFindFolderAttr, gestaltFindFolderPresent));
  319. }
  320.  
  321. Boolean MacHasTempMem(void)
  322. {
  323.     long response;
  324.     
  325.     response = GestaltResponse(gestaltOSAttr);
  326.     return((response & (1 << gestaltTempMemSupport)) &&
  327.              (response & (1 << gestaltRealTempMemory)) &&
  328.              (response & (1 << gestaltTempMemTracked)));
  329. }
  330.  
  331. /* true if there's a console window we can use printf with */
  332. Boolean MacHasConsole(void)
  333. {
  334.     return(true);
  335. }
  336.  
  337. /* true if we're profiling the code */
  338. Boolean MacHasProfiler(void)
  339. {
  340.     return(PROFILE);
  341. }
  342.  
  343.